home *** CD-ROM | disk | FTP | other *** search
/ The Programmer Disk / The Programmer Disk (Microforum).iso / xpro / c / pro22 / cbrecfir.c < prev    next >
Text File  |  1990-06-20  |  2KB  |  80 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)cbrecfir.c    1.4 - 90/06/20" */
  5.  
  6. /* ansi headers */
  7. #include <errno.h>
  8.  
  9. /* library headers */
  10. #include <lseq.h>
  11.  
  12. /* local headers */
  13. #include "cbase_.h"
  14.  
  15. /*man---------------------------------------------------------------------------
  16. NAME
  17.      cbrecfirst - first cbase record
  18.  
  19. SYNOPSIS
  20.      #include <cbase.h>
  21.  
  22.      int cbrecfirst(cbp)
  23.      cbase_t *cbp;
  24.  
  25. DESCRIPTION
  26.      The cbrecfirst function positions the record cursor of cbase cbp
  27.      on the first record.
  28.  
  29.      cbrecfirst will fail if one or more of the following is true:
  30.  
  31.      [EINVAL]       cbp is not a valid cbase pointer.
  32.      [CBELOCK]      cbp is not locked.
  33.      [CBENOPEN]     cbp is not open.
  34.      [CBENREC]      cbp is empty.
  35.  
  36. SEE ALSO
  37.      cbreccnt, cbreclast, cbrecnext, cbrecprev.
  38.  
  39. DIAGNOSTICS
  40.      Upon successful completion, a value of 0 is returned.  Otherwise,
  41.      a value of -1 is returned, and errno set to indicate the error.
  42.  
  43. ------------------------------------------------------------------------------*/
  44. int cbrecfirst(cbp)
  45. cbase_t *cbp;
  46. {
  47.     /* validate arguments */
  48.     if (!cb_valid(cbp)) {
  49.         errno = EINVAL;
  50.         return -1;
  51.     }
  52.  
  53.     /* check if not open */
  54.     if (!(cbp->flags & CBOPEN)) {
  55.         errno = CBENOPEN;
  56.         return -1;
  57.     }
  58.  
  59.     /* check if not locked */
  60.     if (!(cbp->flags & CBLOCKS)) {
  61.         errno = CBELOCK;
  62.         return -1;
  63.     }
  64.  
  65.     /* check if cbp is empty */
  66.     if (lsreccnt(cbp->lsp) == 0) {
  67.         errno = CBENREC;
  68.         return -1;
  69.     }
  70.  
  71.     /* set cursor to first record */
  72.     if (lsfirst(cbp->lsp) == -1) {
  73.         CBEPRINT;
  74.         return -1;
  75.     }
  76.  
  77.     errno = 0;
  78.     return 0;
  79. }
  80.